/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2023. All rights reserved.
 * Description: UDK fbarray defines
 * Author: -
 * Create: 2021.6.22
 */
#ifndef UDK_FBARRAY_H
#define UDK_FBARRAY_H

#include <stdint.h>

#include "udk_rwlock.h"

#define UDK_FBARRAY_NAME_LEN 64

struct udk_fbarray {
    char name[UDK_FBARRAY_NAME_LEN]; /* name associated with an array */
    uint32_t count;                  /* number of entries stored */
    uint32_t len;                    /* current length of the array */
    uint32_t elt_sz;                 /* size of each element */
    void *data;                      /* data pointer */
    udk_rwlock_t rwlock;             /* multiprocess lock */
};

int udk_fbarray_init(struct udk_fbarray *arr, const char *name, uint32_t len, uint32_t elt_sz);
int udk_fbarray_attach(struct udk_fbarray *arr);
int udk_fbarray_destroy(struct udk_fbarray *arr);
void *udk_fbarray_get(const struct udk_fbarray *arr, uint32_t idx);
int udk_fbarray_find_idx(const struct udk_fbarray *arr, const void *elt);
int udk_fbarray_set_used(struct udk_fbarray *arr, uint32_t idx);
int udk_fbarray_set_free(struct udk_fbarray *arr, uint32_t idx);
int udk_fbarray_find_next_free(struct udk_fbarray *arr, uint32_t start);
int udk_fbarray_find_next_used(struct udk_fbarray *arr, uint32_t start);
#endif
